<template>

    <el-form :inline="true" :model="formData" class="demo-form-inline">
          <el-form-item>
              <el-input v-model="formData.name" placeholder="请输入关键字" clearable @change="callPoApi" />
          </el-form-item>
          
          <el-form-item>
              <enum  v-model="formData.status" enumName="PoStatus" ></enum>
          </el-form-item>
          <el-form-item>
              <el-button type="primary" @click="onSubmit">查询</el-button>
          </el-form-item>
      </el-form>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column fixed prop="id" label="id" width="150" />
        <el-table-column prop="vendorName" label="Name" width="120" />
        <el-table-column prop="poDate" label="日期" width="120" />
        <el-table-column prop="statusX" label="状态" width="120" />
        <el-table-column prop="totalPrice" label="总价" width="120" />
        <el-table-column prop="brief" label="备注" width="120" show-overflow-tooltip />
        <el-table-column prop="lastUpdateBy" label="更新人" width="120"  :formatter="formatter"/>
        <el-table-column prop="lastUpdateTime" label="更新时间" width="120" :formatter="formatter"/> 
        <el-table-column fixed="right" label="Operations" min-width="140">
          <template #default="scope">
            <el-button  type="primary" size="small"  @click="edit(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination background layout="total, prev, pager, next" :total="pageData.total" :page-size="pageData.pageSize"
    @current-change="pageChange">
    </el-pagination>
    </template>
    
    <script lang="ts" setup>
    import { ref ,reactive,onMounted } from 'vue'
    import { poApi } from '@/api';
    import { dayjs , ElMessageBox, ElMessage, rowContextKey} from 'element-plus'
    import Enum from '@/components/Enum.vue';
    import {useRouter} from 'vue-router'
    const formData = reactive({
      name: '',
      status:1,
      pcc:[]
    })
    const pageData = reactive({
    total: 0,
    pageSize: 5,
    pageNum: 1

})
    const router = useRouter()
    const tableData = ref([])
   const edit=(row: any) => {
    router.push({name: 'po.edit',query: { id: row.id }})
    }
    const pageChange=(pageNum:number)=>{
    pageData.pageNum=pageNum
    callPoApi()
  }
  
    const callPoApi=()=>{
      let params={
        pageNum:pageData.pageNum,
        pageSize:pageData.pageSize,
        name:formData.name==""?undefined:formData.name,
        status:formData.status==0?undefined:formData.status,

      }
  
      poApi.select.call(params).then(res=>{

          pageData.total = res.count
          tableData.value=res.items
          console.log(res)
      })
    }
   
    const formatter = (row: any, column: any, cellValue: any, index: number) => {
  
      if (column.property === 'lastUpdateTime') {
      return dayjs(cellValue).format('YY年MM月DD HH:mm')
      } else if (column.property === 'lastUpdateBy') {
      return cellValue + " 同志"
      }
      return cellValue
  }
  
    onMounted(() => {
      callPoApi()
    
      })
  
    const onSubmit = () => {
      callPoApi()
    }
    </script>